package com.zhxh.nzpos.setting;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.zhxh.nzpos.BaseActivity;
import com.zhxh.nzpos.R;
import com.zhxh.nzpos.view.CustomDatePicker;

/**
 * 时间设定
 * 
 * @author wangzt
 *
 */
public class TimeSettingActivity extends BaseActivity {
	
	private Calendar fromCal = Calendar.getInstance();
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_time);
        initViews();
    }
	
	private void initViews() {
		final EditText hour = (EditText) findViewById(R.id.setting_hour);
		final EditText minute = (EditText) findViewById(R.id.setting_minute);
		final EditText ampm = (EditText) findViewById(R.id.setting_ampm);
		
		final EditText fromDate = (EditText)findViewById(R.id.setting_date);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		fromDate.setText(simpleDateFormat.format(fromCal.getTime()));
		
		final CustomDatePicker fromPicker = new CustomDatePicker(this, fromDate, fromCal);
		fromDate.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				fromPicker.updateDate();
				fromPicker.show();
			}
		});
		
		ImageView okBtn = (ImageView) findViewById(R.id.password_setting_ok_btn);
		okBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO校验并保存密码
				if( hour.getText().toString().length() == 0 ){
					hour.setError( "小时不能为空" );
					return;
					
				}
				if( minute.getText().toString().length() == 0 ){
					minute.setError( "分钟不能为空" );
					return;
					
				}

				Toast.makeText(getApplicationContext(), "系统时间设置成功", Toast.LENGTH_SHORT).show();
				finish();
			}
		});
/*		ImageView cancelBtn = (ImageView) findViewById(R.id.password_setting_cancel_btn);
		cancelBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});*/
	}
}
